/**
 * Description:
 * Class Name:subject2
 * Date:2022/1/25 15:52
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第5章_面向对象_上.课后练习;


public class charpter5_subject2 {
    static Student[] student_array;     // 推荐用这种方式定义数组，因为符合 type name 的声明格式

    // 通过name、email、address查询数据的方法，若有则返回数组成员的索引，若无则返回-1
    public static int search_member_by_attrs(String search_string, Student[] student_array){
        int index = 0;
        for (var each: student_array){
            if (search_string == each.getName())break;
            if (search_string == each.getEmail())break;
            if (search_string == each.getAddress())break;
            index++;
        }
        if (index >= student_array.length)return -1;
        else return index;
    }

    public static void main(String[] args) {
        var student_a = new Student("小明", 18, "男", "16620220125", "斐济", "idontcar@163.com");
        var student_b = new Student("小红", 16, "女", "19987654321", "内华达", "idoreallycare@163.com");

        /*下面开始初始化数组*/
        student_array = new Student[] {student_a, student_b};
        int member_index;
        member_index = search_member_by_attrs("红", student_array);
        if (member_index < 0) System.out.println("抱歉，未查找到包含相应内容的成员");
        else {
            System.out.println("您查找的成员索引是" + member_index);
        }
    }
}
